1
|
|
|
const { app, ipcMain } = require('electron'); |
2
|
|
|
const path = require("path"); |
|
|
|
|
3
|
|
|
const Window = require("./Window"); |
|
|
|
|
4
|
|
|
const AppMenu = require("./AppMenu"); |
|
|
|
|
5
|
|
|
const Store = require('electron-store'); |
|
|
|
|
6
|
|
|
const EventEmitter = require('events'); |
|
|
|
|
7
|
|
|
const SaveFile = require('./SaveFile'); |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* App Singleton (Wrapper around electron app singleton var) |
11
|
|
|
*/ |
12
|
|
|
module.exports = class App extends EventEmitter { |
13
|
|
|
constructor() { |
14
|
|
|
super(); |
15
|
|
|
|
16
|
|
|
// Make Single Instance and ensure single instance |
17
|
|
|
// if (app.requestSingleInstanceLock()) { |
18
|
|
|
// this.quit(); |
19
|
|
|
// return; |
20
|
|
|
// } |
21
|
|
|
//app.on('second-instance', this.onSecondInstance.bind(this)); |
22
|
|
|
|
23
|
|
|
// Electron app var |
24
|
|
|
this.app = app; |
25
|
|
|
|
26
|
|
|
// Window |
27
|
|
|
this.mainWindow = null; |
28
|
|
|
|
29
|
|
|
// Is development or not |
30
|
|
|
this.isDev = process.env.DEV |
31
|
|
|
? (process.env.DEV.trim() == "true") |
32
|
|
|
: false; |
33
|
|
|
|
34
|
|
|
// Adjust process working directory depending on dev enviroment or not |
35
|
|
|
if (this.isDev) |
36
|
|
|
process.chdir(path.join(__dirname, '../src')); |
|
|
|
|
37
|
|
|
else |
38
|
|
|
process.chdir(path.join(__dirname, '../dist/pokered-save-editor')); |
39
|
|
|
|
40
|
|
|
this.store = new Store(); |
|
|
|
|
41
|
|
|
this.saveFile = new SaveFile(this); |
|
|
|
|
42
|
|
|
|
43
|
|
|
// App Icon |
44
|
|
|
this.icon = 'assets/icons/512x512.png'; |
45
|
|
|
|
46
|
|
|
// Set Name |
47
|
|
|
app.setName("Pokered Save Editor"); |
48
|
|
|
|
49
|
|
|
// App events to hook into for wrapper |
50
|
|
|
app.on('ready', this.createWindow.bind(this)); |
51
|
|
|
app.on('window-all-closed', this.quit.bind(this)); |
52
|
|
|
|
53
|
|
|
ipcMain.on('ipcFrom', this.onIpcFrom.bind(this)); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
onIpcFrom(sender, event, ...args) { |
57
|
|
|
this.emit(`ipcFrom-${event}`, ...args); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
onSecondInstance(argv, cwd) { |
|
|
|
|
61
|
|
|
if (this.mainWindow) |
62
|
|
|
this.mainWindow.reOpen(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
createWindow() { |
66
|
|
|
// Menu must be called around this time so it's placed here |
67
|
|
|
this.menu = new AppMenu(this); |
|
|
|
|
68
|
|
|
this.mainWindow = new Window(this); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
quit() { |
72
|
|
|
app.quit(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|